// i.r(t), i.d(t, { ErrorType: () => f, default: () => ErrorGui })
import Module from "./Module"
import LocaleModule from "./LocaleModule"
import LangKey from "../constant/lang.key"
import browserUtil from "../utils/browser.util"
import Engine from "../Engine"
import EngineContext from "../EngineContext"
const d = e => ({
    problem: "",
    solution: e.t(LangKey.ERROR_BROWSER_SOLUTION),
    explanation: e.t(LangKey.ERROR_BROWSER_EXPLANATION),
    actions: browserUtil.isMobile()
      ? ""
      : [
          "<div id='browser-tiles'>",
          "<a href='https://www.google.com/chrome/browser/' target='_blank'>",
          "<div class='tile'>",
          `<img src=${"./images/chrome.png"}>`,
          "</div>",
          "</a>",
          "<a href='https://www.mozilla.org/en-US/firefox/new/' target='_blank'>",
          "<div class='tile'>",
          `<img src=${"./images/firefox.png"}>`,
          "</div>",
          "</a>",
          "<a href='https://www.microsoft.com/en-us/edge' target='_blank'>",
          "<div class='tile'>",
          `<img src=${"./images/edge.png"}>`,
          "</div>",
          "</a>",
          "<a href='https://support.apple.com/en-us/HT204416' target='_blank'>",
          "<div class='tile'>",
          `<img src=${"./images/safari.png"}>`,
          "</div>",
          "</a>",
          "</div>"
        ].join("")
  }),
  u = e =>
    Object.assign(Object.assign({}, d(e)), {
      problem: `${e.t(LangKey.ERROR_WEBGL_UNSUPPORTED_PROBLEM)}`
    }),
  p = "https://support.com/hc/articles/208220058",
  m = e => {
    const t = p,
      i = browserUtil.isMobile()
        ? e.t(LangKey.ERROR_GENERIC_ACTIONS_MOBILE, { "support-url": t })
        : e.t(LangKey.ERROR_GENERIC_ACTIONS, {
            "browsers-url": "#install-browser",
            "support-url": t
          })
    return {
      problem: e.t(LangKey.ERROR_GENERIC_PROBLEM),
      solution: e.t(LangKey.ERROR_GENERIC_SOLUTION),
      explanation: "",
      actions: i
    }
  },
  g = e => {
    const t = e.t(LangKey.ERROR_LOADING_FAILED_ACTIONS, {
      "support-url": "https://support.3dyunzhan.com/hc/articles/208220058"
    })
    return {
      problem: e.t(LangKey.ERROR_LOADING_FAILED_PROBLEM),
      solution: "",
      explanation: "",
      actions: t
    }
  }
const f = {
  1: "UNSUPPORTED",
  2: "WEBGL",
  3: "GENERIC",
  GENERIC: 3,
  UNSUPPORTED: 1,
  WEBGL: 2
}
export default class ErrorGui extends Module {
  container: HTMLElement
  problem: HTMLElement
  solution: HTMLElement
  explanation: HTMLElement
  actions: HTMLElement
  localeModule: LocaleModule
  constructor() {
    super()
    this.name = "error-gui"
  }
  async init(e, t: EngineContext) {
    this.container = document.querySelector("#error-container")
    this.problem = document.querySelector("#error-problem")
    this.solution = document.querySelector("#error-solution")
    this.explanation = document.querySelector("#error-explanation")
    this.actions = document.querySelector("#error-actions")
    this.localeModule = await t.getModule(LocaleModule)
    return Promise.resolve()
  }
  showError(e: number) {
    switch (e) {
      case f.UNSUPPORTED:
        this.populateErrorScreen(u)
        break
      case f.WEBGL:
        this.populateErrorScreen(m)
        break
      case f.GENERIC:
      default:
        this.populateErrorScreen(g)
    }
    const t = this.actions.querySelector('[href="#install-browser"]')
    t &&
      t.addEventListener("click", e => {
        e.preventDefault(), this.populateErrorScreen(d)
      })
  }
  populateErrorScreen(e) {
    const t = e(this.localeModule)
    this.container.classList.remove("hidden")
    this.problem.innerText = t.problem
    this.solution.innerText = t.solution
    this.explanation.innerText = t.explanation
    this.actions.innerHTML = t.actions
  }
}
// export default {
//   ErrorType: f,
//   default: ErrorGui
// }
